#!/bin/sh

: ${top_builddir:=../..}
: ${top_srcdir:=../..}
: ${builddir:=.}

trap 'exit' 1 2 3 15
trap '. $IBUST_ADDRESS_FILE; kill $IBUST_DAEMON_PID &> /dev/null; rm -fr components $IBUST_ADDRESS_FILE' EXIT

# copy some component files necessary for testing, under components/
copy_component() {
    file=$1
    base=`basename $file`
    if test -f $file.in; then
	mkdir -p components
	( libexecdir=`dirname $file`;
	    s=`cat $file.in`;
	    eval "echo \"${s}\"" ) > components/$base
    fi
}
copy_component "$top_srcdir/engine/simple.xml"
copy_component "$top_srcdir/conf/memconf/memconf.xml"

# start ibust-daemon
IBUST_COMPONENT_PATH=$PWD/components
export IBUST_COMPONENT_PATH

IBUST_ADDRESS_FILE=$PWD/ibust-daemon.log
export IBUST_ADDRESS_FILE

$top_builddir/bus/ibust-daemon \
    --daemonize \
    --cache=none \
    --panel=disable \
    --config=default \
    --verbose

# wait until all necessary components are up
sleep 1

# run tests
"$@"
